package com.xingfudazi.common.utils;


import com.xingfudazi.common.core.domain.BaseEntity;
import com.xingfudazi.common.core.domain.CustomBaseEntity;
import com.xingfudazi.common.enums.DBDataStatus;

import java.time.LocalDateTime;
import java.util.Date;

public class BeanFillUtil {

    private BeanFillUtil() {

    }

    public static void saveFill(CustomBaseEntity baseEntity) {
        baseEntity.setCreateBy(SecurityUtils.getUsername());
        baseEntity.setCreateTime(LocalDateTime.now());
        baseEntity.setDelFlag(DBDataStatus.OK.getCode());
        baseEntity.setUpdateTime(null);
        baseEntity.setUpdateBy(null);
    }


    public static void updateFill(CustomBaseEntity baseEntity) {
        baseEntity.setUpdateBy(SecurityUtils.getUsername());
        baseEntity.setUpdateTime(LocalDateTime.now());
        baseEntity.setCreateTime(null);
        baseEntity.setCreateBy(null);
    }

    public static void saveFill(BaseEntity baseEntity) {
        baseEntity.setCreateBy(SecurityUtils.getUsername());
        baseEntity.setCreateTime(new Date());
        baseEntity.setUpdateTime(null);
        baseEntity.setUpdateBy(null);
    }


    public static void updateFill(BaseEntity baseEntity) {
        baseEntity.setUpdateBy(SecurityUtils.getUsername());
        baseEntity.setUpdateTime(new Date());
        baseEntity.setCreateTime(null);
        baseEntity.setCreateBy(null);
    }
}
